﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Viewer.Human
{
    /// <summary>
    /// UserControlHuman.xaml 的交互逻辑
    /// </summary>
    public partial class UserControlHuman : UserControl
    {



        /// <summary>
        /// 脸面向的方向，以东为0度。顺时针增加数值。
        /// </summary>
        public double FaceTo
        {
            get { return (double)GetValue(FaceToProperty); }
            set { SetValue(FaceToProperty, value); }
        }

        // Using a DependencyProperty as the backing store for FaceTo.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty FaceToProperty =
            DependencyProperty.Register("FaceTo", typeof(double), typeof(UserControlHuman), new PropertyMetadata(0.0d));





        public UserControlHuman()
        {
            InitializeComponent();
            PeriodicTimer timer = new PeriodicTimer(TimeSpan.FromMilliseconds(1000));
            Task.Run(async () =>
            {
                while (await timer.WaitForNextTickAsync())
                {
                    // 在这里执行定时任务
                    Dispatcher.Invoke(() =>
                    {
                        this.FaceTo += 10;
                        if (this.FaceTo >= 360)
                        {
                            this.FaceTo = FaceTo%360;
                        }
                    });
                }
            });
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var myPosition = this.Margin.ToString();
            var onFlool = (this.Parent as Grid).RenderSize;
            MessageBox.Show($"你好,我是你创建的小人! wo在这里哦：{myPosition} wo的脚下有这么大的地面：{onFlool.ToString()}");

            
        }
    }
}
